package com.yang.service.adminimpl;

import com.yang.bean.*;
import com.yang.bean.zdd.bo.FloorGoodsListBo;
import com.yang.bean.zdd.vo.IndexVo;
import com.yang.mapper.*;
import com.yang.service.admin.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName WXHomeServiceImpl
 * @Description TODO
 * @Author zhangdongdong
 * @Date 2022/9/9 15:36
 * @Version 1.0
 */
@Service
public class WXHomeServiceImpl implements HomeService {
    @Autowired
    MarketADMapper adMapper;
    @Autowired
    MarketBrandMapper brandMapper;
    @Autowired
    MarketCategoryMapper categoryMapper;
    @Autowired
    MarketCouponMapper couponMapper;
    @Autowired
    MarketGoodsMapper goodsMapper;
    @Autowired
    MarketTopicMapper topicMapper;

    /** 
     * @description: 商城首页显示内容
     * @param: 
     * @return: com.yang.bean.zdd.vo.IndexVo
     * @author zhangdongdong
     * @date: 2022/9/11 10:32
     */ 
    @Override
    public IndexVo index() {
        IndexVo data = new IndexVo();

        //查询banner->marketAd
        MarketADExample adExample = new MarketADExample();
        List<MarketAD> banner = adMapper.selectByExample(adExample);
        data.setBanner(banner);

        //查询brandList
        MarketBrandExample brandExample = new MarketBrandExample();
        List<MarketBrand> brandList = brandMapper.selectByExample(brandExample);
        data.setBrandList(brandList);

        //查询channel->category
        MarketCategoryExample categoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = categoryExample.createCriteria();
        criteria.andLevelEqualTo("L1");
        List<MarketCategory> channel = categoryMapper.selectByExample(categoryExample);
        data.setChannel(channel);

        //查询couponList
        MarketCouponExample couponExample = new MarketCouponExample();
        List<MarketCoupon> couponList = couponMapper.selectByExample(couponExample);
        data.setCouponList(couponList);

        //查询floorGoodsList
        List<MarketCategory> pidAll = categoryMapper.selectPidAll();
        List<FloorGoodsListBo> floorGoodsListBoList = new ArrayList();
        new FloorGoodsListBo();
        for (MarketCategory pidS : pidAll) {
            FloorGoodsListBo floorGoodsListBo = new FloorGoodsListBo();
            MarketGoodsExample goodsExample1 = new MarketGoodsExample();
            goodsExample1.createCriteria().andCategoryIdEqualTo(pidS.getId());
            List<MarketGoods> floorGoodsList = goodsMapper.selectByExample(goodsExample1);

            floorGoodsListBo.setGoodsList(floorGoodsList);
            floorGoodsListBo.setId(pidS.getId());
            floorGoodsListBo.setName(pidS.getName());

            floorGoodsListBoList.add(floorGoodsListBo);
        }
        data.setFloorGoodsListBoList(floorGoodsListBoList);

        //查询hotGoodsList
        MarketGoodsExample goodsExample2 = new MarketGoodsExample();
        goodsExample2.createCriteria().andIsHotEqualTo(true);
        List<MarketGoods> hotGoodsList = goodsMapper.selectByExample(goodsExample2);
        data.setHotGoodsList(hotGoodsList);

        //查询newGoodsList
        MarketGoodsExample goodsExample3 = new MarketGoodsExample();
        goodsExample3.createCriteria().andIsNewEqualTo(true);
        List<MarketGoods> newGoodsList = goodsMapper.selectByExample(goodsExample3);
        data.setNewGoodsList(newGoodsList);

        //查询topicList
        MarketTopicExample topicExample = new MarketTopicExample();
        List<MarketTopic> topicList = topicMapper.selectByExample(topicExample);
        data.setTopicList(topicList);

        return data;
    }
}
